﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Reflection;

namespace CPlase.Internal
{
    public static class InstanceActivator
    {
        public static IRoleEchoCommand GenerateEchoCommandObject(string Command)
        {
            return Generate<IRoleEchoCommand>(Command);
        }

        public static IRoleEchoCommand GenerateEchoCommandObject(Type ObjectType)
        {
            return Generate<IRoleEchoCommand>(ObjectType);
        }

        public static IWorkerQueueHandler GenerateQueueHandler(string QueueType)
        {
            return Generate<IWorkerQueueHandler>(QueueType);
        }

        public static IWorkerQueueHandler GenerateQueueHandler(Type QueueObjectType)
        {
            return Generate<IWorkerQueueHandler>(QueueObjectType);
        }

        public static T Generate<T>(string ObjectTypeString) where T : class
        {
            try
            {
                return Generate<T>(Type.GetType(ObjectTypeString));
            }
            catch { }
            return null;
        }

        public static T Generate<T>(Type ObjectType) where T : class
        {
            try
            {
                Object Obj = Activator.CreateInstance(ObjectType);
                if (Obj is T) return Obj as T;
            }
            catch { }
            return null;
        }


    }
}